package com.exp2.caloriedaily.utils

import android.util.Log
import com.jjoe64.graphview.series.DataPoint
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.*

object DateUtils {

    fun graphData(date:String):Double{
        var time=date.split("-")

        var result=((time[0].toDouble()%100)*100+time[1].toDouble())*100+time[2].toDouble()
/*        Log.d("year",time[0])
        Log.d("year",time[1])
        Log.d("year",time[2])
        Log.d("result",result.toString())*/

        return result
    }

    /**
     * 字符串转时间戳
     * 开始时间
     * @param timeString 年月日的String
     * @return 转化年月日为时间戳String（适配PHP 除以1000）-后台是java的话则不用除以1000
     */
    fun getTimeStart(timeString: String): String? {
        var timeStamp: String? = null
        val sdf = SimpleDateFormat("yyyy-MM-dd")
        val d: Date
        try {
            d = sdf.parse(timeString)
            var l = d.time
/*            if (l.toString().length > 10) {
                l = l / 1000
            }*/
            timeStamp = l.toString()
        } catch (e: ParseException) {
            e.printStackTrace()
        }
        return timeStamp
    }

    /**
     * 字符串转时间戳
     * 结束时间- 追加23小时59分钟
     * @param timeString 年月日的String
     * @return 转化年月日为时间戳String（适配PHP 除以1000）-后台是java的话则不用除以1000
     */
    fun getTimeEnd(timeString: String): String? {
        var timeStamp: String? = null
        val sdf = SimpleDateFormat("yyyy-MM-dd-HH:mm")
        val d: Date
        try {
            d = sdf.parse((timeString + "23:59"))
            var l = d . time
            /*if (l.toString().length > 10) {
                l = l / 1000
            }*/
            timeStamp = l.toString()
        } catch (e: ParseException) {
            e.printStackTrace()
        }
        return timeStamp
    }
}
